package correct.day10;

import java.util.Scanner;

public class Test2 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int ret = 0, prevMin = in.nextInt();
        int x = 0;
        for(int i = 1; i < n; i++)
        {
            x = in.nextInt();
            ret = Math.max(ret, x - prevMin);
            prevMin = Math.min(prevMin, x);
        }

        System.out.println(ret < 0 ? 0 : ret);
    }

    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        int[] arr1 = new int[n];
        for(int i = 0; i < n; i++) {
            int j = i + 1;
            int max = 0;
            while(j < n) {
                max = Math.max(max, arr[j] - arr[i]);
                j++;
            }
            arr1[i] = max;
        }
        int ret = arr1[0];
        for(int i = 0; i < n; i++) {
            if(ret < arr1[i]) {
                ret = arr1[i];
            }
        }
        System.out.println(ret);

//        for(int i = 1; i < n; i++) {
//            int min = 0;
//            int j = i - 1;
//            while(min >= 0) {
//                min = Math.min(min, arr[j]);
//                j--;
//            }
//            arr1[i] = arr[i] - arr[min];
//        }
//        int ret = arr1[0];
//        for(int i = 0; i < n; i++) {
//            if(ret < arr1[i]) {
//                ret = arr1[i];
//            }
//        }
//        System.out.println(ret);
    }
}
